<template>
  <div class="hot_league">
    <div class="hot_header">
      <div class="title AlibabaPuHuiTi_2_85_">{{ languageJson.home.hot }}</div>
    </div>
    <div class="hot_content" v-loading="homeState.allleague.loading">
      <template v-if="hotleagueList.length > 0">
        <div
          class="hot_item"
          v-for="item in hotleagueList"
          :key="item.data.league_id"
          @click="homeStore.changeactiveleague(item.data.league_id)"
          :style="
            homeState.activecountryStyle == '' && homeState.activeleague.includes(item.data.league_id)
              ? 'color: #3711d8;'
              : ''
          "
        >
          <img :src="item.icon" style="width: 20px; height: 20px; border-radius: 50%" alt="" />
          <div style="margin-left: 8px" class="AlibabaPuHuiTi_2_55_">
            {{ languageType == 'zh' ? item.data.league_name : item.data.league_en }}
          </div>
        </div>
      </template>
      <template v-else>
        <el-empty :image-size="60" style="padding: 0" :description="languageJson.message.nodata" />
      </template>
    </div>
  </div>
</template>

<script setup>
const { homeStore, homeState } = inject('HomeStore')
const languageJson = inject('languageJson')
const languageType = inject('languageType')
const hotleagueList = computed(() => {
  let a = []

  homeState.allleague.data.forEach(item => {
    if (homeState.activesport == 'soccer') {
      if (item.country_id == '120') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100021') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }

      if (item.country_id == '34') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100030') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }

      if (item.country_id == '53') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100026') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }

      if (item.country_id == '30') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100028') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }

      if (item.country_id == '36') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100032') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }
    } else {
      if (item.country_id == '361') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100744') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }
      if (item.country_id == '363') {
        Object.keys(item.leagues).forEach(key => {
          if (key == 'league_100828') {
            a.push({
              icon: item.icon,
              data: item.leagues[key],
            })
          }
        })
      }
    }
  })

  return a
})
</script>

<style lang="scss" scoped>
.hot_league {
  width: 100%;
  height: 188px;
  background: #fff;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}
.hot_header {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .title {
    font-family: AlibabaPuHuiTi_2_85_;
    font-size: 16px;
    font-weight: bold;
    color: #000;
  }
  .more {
    font-family: AlibabaPuHuiTi_2_55_;
    font-size: 12px;
    color: #999;
    cursor: pointer;
  }
}
.hot_content {
  margin: 12px 0;
  display: flex;
  flex-direction: column;
}
.hot_item {
  display: flex;
  align-items: center;
  font-family: AlibabaPuHuiTi_2_55_;
  font-size: 14px;
  color: #000;
  margin-bottom: 8px;
  cursor: pointer;
}
</style>